package com.qingjiang.projectschedule.utils;

import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.stereotype.Component;

@Component
public class ExcelTemplateGenerator {
    //private static Workbook workbook = new XSSFWorkbook();

    public static Workbook ExcelHeader(String color) {
        Workbook workbook = new XSSFWorkbook();
        //创建工作薄
        //创建工作表
        Sheet sheet = workbook.createSheet("Sheet1");

        //创建标题行
        Row headerRow = sheet.createRow(0);
        //设置样式
        CellStyle headerStyle = workbook.createCellStyle();
        Font headerFont = workbook.createFont();
        headerFont.setFontName("黑体");
        headerFont.setFontHeightInPoints((short) 8);
        headerStyle.setFont(headerFont);
        headerStyle.setAlignment(HorizontalAlignment.CENTER);
        headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
        headerStyle.setWrapText(true);


        Cell headerRowCell_0 = headerRow.createCell(0);
        headerRowCell_0.setCellValue("序号");
        headerRowCell_0.setCellStyle(headerStyle);
        //sheet.addMergedRegion(new CellRangeAddress(0,1,0,0));

        Cell headerRowCell_1 = headerRow.createCell(1);
        headerRowCell_1.setCellValue("责任单位");
        headerRowCell_1.setCellStyle(headerStyle);
        sheet.setColumnWidth(1, 16 * 256 + 185);
        //sheet.addMergedRegion(new CellRangeAddress(0,1,1,1));

        Cell headerRowCell_2 = headerRow.createCell(2);
        headerRowCell_2.setCellValue("项目名称");
        headerRowCell_2.setCellStyle(headerStyle);
        sheet.setColumnWidth(2, 40 * 256 + 185);
        //sheet.addMergedRegion(new CellRangeAddress(0,1,2,2));
        String nodeColName;
        String reasonColName;
        if ("yellow".equals(color)) {
            nodeColName = "超期节点名称";
            reasonColName = "滞后原因";
        } else {
            nodeColName = "考核节点名称";
            reasonColName = "滞后原因";
        }
        Cell headerRowCell_3 = headerRow.createCell(3);
        headerRowCell_3.setCellValue(nodeColName);
        headerRowCell_3.setCellStyle(headerStyle);
        sheet.setColumnWidth(3, 40 * 256 + 185);
        //sheet.addMergedRegion(new CellRangeAddress(0,1,3,3));

        Cell headerRowCell_4 = headerRow.createCell(4);
        headerRowCell_4.setCellValue(reasonColName);
        headerRowCell_4.setCellStyle(headerStyle);
        sheet.setColumnWidth(4, 16 * 256 + 185);
        //sheet.addMergedRegion(new CellRangeAddress(0,1,4,4));

        return workbook;
    }


}
